//
//  WWindow.m
//  caishuitong
//
//  Created by 企友软mac on 2017/5/31.
//  Copyright © 2017年 zhangxy. All rights reserved.
//

#import "WWindow.h"
#import "AudioPlayerManage.h"

@interface WWindow ()<PlayerTabBarToolDelegate> 

@end

@implementation WWindow

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = [UIColor clearColor];
        //如果想在 alert 之上，则改成 + 2
        self.windowLevel = UIWindowLevelAlert + 1;
        self.rootViewController = [UIViewController new];
        [self makeKeyAndVisible];
        
        _playTool = [[[NSBundle mainBundle]loadNibNamed:@"PlayerTabBarTool" owner:self options:nil] lastObject];
        _playTool.frame = CGRectMake(0, 0, frame.size.width, frame.size.height);

//        [_playTool.btnPlay setImageEdgeInsets:UIEdgeInsetsMake(5, 5, 5, 5)];
        _playTool.delegatePlayTool = self;
        [self addSubview:_playTool];
        
        AudioPlayerManage *playerManage = [AudioPlayerManage playerManage];
        playerManage.delegatePlayer = self;
    }
    return self;
}

- (void)dissmissWindow{
    self.hidden = YES;
}

- (void)showWindow{
    self.hidden = NO;
}

- (void)btnPlayerToolClick:(UIButton *)sender {
    
    [[NSNotificationCenter defaultCenter] postNotificationName:PLAYTOGGLE object:nil];

    AudioPlayerManage *playerManage = [AudioPlayerManage playerManage];

    if (sender.tag == 50) {
        
        if ([WShareUtil sharedData].isPlay) {
            [playerManage audioPlayerPlayPrevious];
        }

    }else if (sender.tag == 51) {
        sender.selected = !sender.selected;
        
        if (sender.selected) {
            [sender setImage:[UIImage imageNamed:@"pauseList"] forState:UIControlStateNormal];
            [playerManage audioPlayerPlay];
        }else {
            [sender setImage:[UIImage imageNamed:@"Toolplay"] forState:UIControlStateNormal];
            [playerManage audioPlayerPause];
        }

    }else if (sender.tag == 52) {
        
        if ([WShareUtil sharedData].isPlay) {
            [playerManage audioPlayerPlayNext];
        }

    }else if (sender.tag == 53) {
        
        [playerManage audioPlayerPause];

        [self dissmissWindow];
        [WShareUtil sharedData].isShowTool = NO;
        [_playTool.lbPlayTit dismiss];
    }
}

@end
